//
//  IGCommunityTableViewCell.m
//  jingdongfang
//
//  Created by BOE on 2017/8/16.
//  Copyright © 2017年 kevinLY. All rights reserved.
//

#import "IGCommunityTableViewCell.h"

static NSString *const kCommunityCellID = @"kCommunityCellID";
@interface IGCommunityTableViewCell()

@property (nonatomic, strong) UIImageView *imgView;
@property (nonatomic, strong) UILabel *titleLabel;
@property (nonatomic, strong) UILabel *detailLabel;

@property (nonatomic, copy) NSString *img;
@property (nonatomic, copy) NSString *title;
@property (nonatomic, copy) NSString *detail;

@end

@implementation IGCommunityTableViewCell

+ (IGCommunityTableViewCell *)cellWithTableView:(UITableView *)tableView
{
    IGCommunityTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:kCommunityCellID];
    if (!cell) {
        cell = [[IGCommunityTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:kCommunityCellID];
    }
    return cell;
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.contentView.backgroundColor = [UIColor whiteColor];
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        self.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
        
        [self createUI];
    }
    return self;
}

- (void)createUI {
    [self.contentView addSubview:self.imgView];
    [self.contentView addSubview:self.titleLabel];
    [self.contentView addSubview:self.detailLabel];
    
    [self.imgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(kGAP15);
        make.top.mas_equalTo(15);
        make.height.width.mas_equalTo(20);
    }];
    
    [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.imgView.mas_right).offset(kGAP10);
        make.centerY.mas_equalTo(self.imgView.mas_centerY);
        make.width.mas_equalTo(80);
        make.height.mas_equalTo(30);
    }];
    
    [self.detailLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.titleLabel.mas_right).offset(kGAP10);
        make.centerY.mas_equalTo(self.imgView.mas_centerY);
        make.width.mas_equalTo(KSCREENWIDTH - kGAP15 - kGAP10 - kGAP10 - 80);
        make.height.mas_equalTo(30);
    }];
}

- (UIImageView *)imgView {
    if (!_imgView) {
        _imgView = [[UIImageView alloc] init];
    }
    return _imgView;
}

- (UILabel *)titleLabel {
    if (!_titleLabel) {
        _titleLabel = [[UILabel alloc] init];
        _titleLabel.textColor = [UIColor c4Color];
        _titleLabel.font = [UIFont font18];
    }
    return _titleLabel;
}

- (UILabel *)detailLabel {
    if (!_detailLabel) {
        _detailLabel = [[UILabel alloc] init];
        _detailLabel.textColor = [UIColor c5Color];
        _detailLabel.font = [UIFont font18];
    }
    return _detailLabel;
}

- (void)dataWithImg:(NSString *)img title:(NSString *)title detail:(NSString *)detail {
    _img = img;
    _title = title;
    _detail = detail;
    
    _imgView.image = [UIImage imageNamed:img];
    
    _titleLabel.text = title;
    
    _detailLabel.text = detail;
}

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];
    
    // Configure the view for the selected state
}

@end
